package chen.yi.web.controller;

import chen.yi.common.resp.R;
import chen.yi.mapper.dto.login.LoginDTO;
import chen.yi.mapper.vo.login.CodeInfoVO;
import chen.yi.service.service.login.LoginService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 登录控制层
 * @author huat
 **/
@RestController
@RequestMapping("/login")
@Slf4j
public class LoginController {
    private final LoginService loginService;

    @Autowired
    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }

    /**
     * 获取验证码
     * @return 验证码信息
     */
    @GetMapping("/get-code")
    public R<CodeInfoVO> getCode(){
        log.info("开始获取验证码");
        return loginService.getCode();
    }
    /**
     * 登录
     */
    @PostMapping("/do-login")
    public R<?> doLogin(@RequestBody @Validated LoginDTO loginDTO, HttpServletResponse response){
        log.info("登录入参:{}", loginDTO);
        return loginService.doLogin(loginDTO,response);
    }
}
